package com.ruoyi.common.core.result;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author by shixd
 * @date 2021/3/23
 * @desc
 */
@ControllerAdvice
public class ExceptionHandlers {

    /**
     * 处理未知异常
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handle(Exception e) {
        if (e instanceof BusinessException) {
            BusinessException userException = (BusinessException) e;
            return ResultUtils.error(userException.getMessage());
        } else {
            return ResultUtils.error(e.getMessage());
        }
    }

}
